package com.karaku.karaku_collector.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.karaku.karaku_collector.LocalSetting;
import com.karaku.karaku_collector.R;
import com.karaku.karaku_collector.common.binder.BindView;
import com.karaku.karaku_collector.common.binder.OnClick;
import com.karaku.karaku_collector.common.binder.UIBinder;
import com.karaku.karaku_collector.util.actions.Action1;

/**
 * Created by guoping on 2017/10/27.
 */

@BindView(R.layout.view_direction_edit)
public class DirectionEdtView extends FrameLayout {

    @BindView(R.id.rg_direction)
    private RadioGroup rgDirection;
    @BindView(R.id.rb_front)
    private RadioButton rbFront;
    @BindView(R.id.rb_lateral)
    private RadioButton rbLateral;

    private Action1<Integer> callback;

    public DirectionEdtView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        UIBinder.bind(this, this, true);

        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                setVisibility(View.GONE);
            }
        });
    }

    public void show(int direction, Action1<Integer> callback) {
        this.callback = callback;
        if (direction == LocalSetting.DIR_FRONT) {
            rbFront.setChecked(true);
        } else {
            rbLateral.setChecked(true);
        }
        setVisibility(VISIBLE);
    }

    public void hide() {
        callback = null;
        setVisibility(GONE);
    }

    @OnClick(R.id.btn_ok)
    private void ok() {
        if (callback != null) {
            callback.run(rbFront.isChecked() ? LocalSetting.DIR_FRONT : LocalSetting.DIR_LATERAL);
        }
        hide();
    }

}
